import AntModal from "@/components/pt/dialog/AntModal";
import ChangeUser from "@/views/system/user/modules/ChangeUser";
import {
  getBizGongziSetting,
  addBizGongziSetting,
  updateBizGongziSetting,
  findMaxSort,
} from "@/api/biz/bizGongziSetting";

export default {
  name: "CreateForm",
  props: {
    typeOptions: {
      type: Array,
      required: true,
    },
  },
  components: {
    AntModal,
    ChangeUser,
  },
  data() {
    return {
      open: false,
      spinning: false,
      delayTime: 100,
      labelCol: { span: 4 },
      wrapperCol: { span: 14 },
      loading: false,
      total: 0,
      id: undefined,
      formTitle: "添加员工工资",
      // 表单参数
      form: { status: "0" },
      rules: {},
      visible: false,
    };
  },
  filters: {},
  created() {},
  computed: {},
  watch: {},
  mounted() {},
  methods: {
    handleManualShare(user) {
      const u = user[0];
      this.form.userId = u.id;
      this.form.userName = u.name;
      this.form.yuangongId = u.id;
      this.form.yuangongName = u.name;
      this.form.deptId = u.deptId;
    },
    handleOk() {
      this.visible = false;
    },
    handleOpenUser() {
      this.visible = true;
    },
    handleCancel() {
      this.visible = false;
    },
    onClose() {
      this.open = false;
      this.reset();
      this.$emit("close");
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
      this.$emit("close");
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        yuangongId: undefined,

        yuangongName: undefined,

        type: undefined,

        basicSalary: undefined,

        draw: undefined,

        fenrunBi: undefined,

        jijianAmount: undefined,

        status: "0",
      };
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      /** 获取最大编号 */
      findMaxSort().then((response) => {
        this.form.sort = response.data;
        this.formTitle = "添加员工工资";
      });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.open = true;
      this.spinning = !this.spinning;
      const bizGongziSettingId = row.id;
      getBizGongziSetting(bizGongziSettingId).then((response) => {
        this.form = response.data;
        this.formTitle = "修改员工工资";
        this.spinning = !this.spinning;
      });
    },
    /** 提交按钮 */
    submitForm: function () {
      this.$refs.form.validate((valid) => {
        if (valid) {
          const saveForm = JSON.parse(JSON.stringify(this.form));
          if (this.form.id !== undefined) {
            updateBizGongziSetting(saveForm).then((response) => {
              this.$message.success("修改成功", 3);
              this.open = false;
              this.$emit("ok");
              this.$emit("close");
            });
          } else {
            addBizGongziSetting(saveForm).then((response) => {
              this.$message.success("新增成功", 3);
              this.open = false;
              this.$emit("ok");
              this.$emit("close");
            });
          }
        } else {
          return false;
        }
      });
    },
    back() {
      const index = "/biz/gongzisetting/index";
      this.$router.push(index);
    },
  },
};
